package com.oreilly.ez.account;

import org.apache.commons.lang3.RandomStringUtils;

import java.io.FileOutputStream;
import java.util.concurrent.ThreadLocalRandom;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipClient {

    public static void main(String[] args) throws  Exception{
        //这个是压缩之后的文件绝对路径
        FileOutputStream fos = new FileOutputStream(
                "/Users/mac/Desktop/demo.zip");
        ZipOutputStream zipOut = new ZipOutputStream(fos);

        for (int i = 0; i < 10; i++) {

            String text = RandomStringUtils.randomAlphanumeric(10000);
            System.out.println(text);

            // add one file
            ZipEntry zipEntry = new ZipEntry("test/db/random-"+ RandomStringUtils.randomNumeric(6)+".txt");
            zipOut.putNextEntry(zipEntry);

            // write file stream to zip
            byte[] bytes = text.getBytes("UTF-8");

            zipOut.write(bytes);

            zipOut.flush();

            zipOut.closeEntry();
        }


        zipOut.close();

    }
}
